<?php 
/**
 * @todo 小说章节阅读页面
 * @author 马超
 */
define('_VIEW_MODEL_','default');
require_once("./init.php");

$chapterId = isset($_GET['cid'])?(int)$_GET['cid']:errorPrompt('param_error','/'); //章节id
$chapterInfo = $db->getRow("select * from {$telper}chapter where id = '$chapterId'");
if(empty($chapterInfo))errorPrompt('novel_not_exist','/'); //小说不存在


$filePath            = getChapterPath($chapterId);
$fileContent         = file_get_contents($filePath);
$fileContent         = ($fileContent); //带回车换行的内容

$pageSize            = 500; //每页显示记录数
$fileLen			 = function_exists("mb_substr")?mb_strlen($fileContent, 'utf-8'):strlen($fileContent);
$page				 = isset($_GET['page'])?(int)$_GET['page']:1;
$startLen			 = (min($page,ceil($fileLen/$pageSize))-1)*$pageSize;
$pageContent        = csubstr($fileContent,$startLen,500);
require_once INC.'/pageclass.php';
new Page($fileLen,$pageSize,$smartyObj);
//echo $pageContent;exit;
//echo iconv("GBK","UTF-8",$pageContent);exit;
$smartyObj->assign('pagecont',nl2br($pageContent));
header("Content-type:text/vnd.wap.wml;charset=utf-8");
$smartyObj->display('read.tpl');
?>